package com.whiteape.book.ui.adapter;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.whiteape.book.R;
import com.whiteape.book.core.manager.MediaStorageManager;
import com.whiteape.book.model.dto.MediaChapterBean;
import com.whiteape.book.model.type.DownloadStatus;
import com.whiteape.book.model.type.MediaType;
import com.whiteape.book.widget.ChapterButton;

import java.util.ArrayList;
import java.util.List;

public class CatalogSelectAdapter extends BaseQuickAdapter<MediaChapterBean, BaseViewHolder> {

    private List<MediaChapterBean> mSelectedList = new ArrayList<>();
    public CatalogSelectAdapter(int layoutResId, @Nullable List<MediaChapterBean> data) {
        super(layoutResId, data);
    }

    public void setSelectedList(List<MediaChapterBean> chapterBeanList) {
        mSelectedList = chapterBeanList;
    }
    @Override
    protected void convert(BaseViewHolder helper, MediaChapterBean item) {

        ChapterButton chapterButton = helper.getView(R.id.item_chapter_button);

        //这个选择，只给漫画使用
        boolean isChapterCached = MediaStorageManager.isChapterCached(MediaType.MEDIA_TYPE_COMIC, item.getMediaId(), item);
        if (isChapterCached) {
            chapterButton.setSelected(false);
            chapterButton.setDownload(true);
        }else {
            chapterButton.setDownload(false);
            chapterButton.setSelected(mSelectedList.contains(item));
        }

        helper.addOnClickListener(R.id.item_chapter_button);
        helper.setText(R.id.item_chapter_button, item.getName());
    }
}
